package com.fruit.web.vo.genl;

import java.util.List;




import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.fruit.service.IConsultationTypeService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.ConsultationType;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existConsultationType")
@SessionScoped
public class ExistConsultationTypeBean implements java.io.Serializable {

	private SelectItem[] consultationTypeItems;

	public SelectItem[] getConsultationTypeItems() {
		return consultationTypeItems;
	}

	public void setConsultationTypeItems(SelectItem[] consultationTypeItems) {
		this.consultationTypeItems = consultationTypeItems;
	}
	public ExistConsultationTypeBean() {
		
		IConsultationTypeService<ConsultationType,Long> consultationTypeService = (IConsultationTypeService<ConsultationType,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.CONSULTATION_TYPE_SERVICE_BEAN_NAME);
		consultationTypeService.setEntityClass(ConsultationType.class);
		consultationTypeService.setPKClass(Long.class);
		List<ConsultationType> consultationTypes = consultationTypeService.getAll("serialNumber",true);
		SelectItem[] tempConsultationTypeItems = new SelectItem[consultationTypes.size()];
		//set select default 
		if (null != consultationTypes && !(consultationTypes.isEmpty())) {
			for (int i=0; i< tempConsultationTypeItems.length; i++) {
				ConsultationType consultationType = (ConsultationType) consultationTypes.get(i);
				String consultationTypeNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,consultationType.getTypeName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempConsultationTypeItems[i] = new SelectItem(consultationType.getTypeCode(),consultationTypeNameN18);
			}
		}
		this.setConsultationTypeItems(tempConsultationTypeItems);
	}
}
